/**
 * 
 */
package util;

import java.util.List;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;


public class DomainDataContentProvider implements IStructuredContentProvider,
		DomainDataListener<Object> {
	TableViewer viewer;

	@SuppressWarnings("unchecked")
	public Object[] getElements(Object inputElement) {
		return ((DomainData<List<Object>>) inputElement).getList().toArray();
	}

	public void dispose() {
	}

	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		this.viewer = (TableViewer) viewer;

		if (oldInput != null) {
			((DomainData<?>) oldInput).removeListener(this);
		}

		if (newInput != null) {
			((DomainData<?>) newInput).addListener(this);
		}
	}

	public void add(ChipDatum datum) {
		if (viewer != null) {
			viewer.add(datum);
		}
	}

	public void remove(ChipDatum datum) {
		if (viewer != null) {
			viewer.remove(datum);
		}
	}

	public void add(Object datum) {
		if (viewer != null) {
			viewer.add(datum);
		}
	}

	public void remove(Object datum) {
		if (viewer != null) {
			viewer.remove(datum);
		}
	}
	
}